#import <Cocoa/Cocoa.h>
#import "ManagingWindowController.h"

typedef enum {
    RNNewItemSheetItemToolbarItem,
    RNNewItemSheetListToolbarItem,
    RNNewItemSheetStoreToolbarItem,
    RNNewItemSheetAisleToolbarItem,
    RNNewItemSheetCategoryToolbarItem
} RNNewItemSheetToolbarItem;

@class RNCategory;
@class RNList;

@interface RNNewItemSheetController : ManagingWindowController <NSBrowserDelegate> {
    NSTabView *tabView_;
    NSToolbar *toolbar_;
    NSView *bottomBar_;
    NSButton *saveButton_;
    NSTreeController *categoriesController_;
    NSArrayController *storesController_;

    // New category view
    NSView *categoryView_;
    NSTextField *categoryViewNameField_;
    NSBrowser *categoryViewBrowser_;
    
    // New item view
    NSView *itemView_;
    NSTextField *itemViewNameField_;
    NSBrowser *itemViewBrowser_;
    
    // New store view
    NSView *storeView_;
    NSTextField *storeViewNameField_;
    NSMatrix *templateMatrix_;
    NSButton *createAislesCheckBox_;

    // New aisle view
    NSView *aisleView_;
    NSTextField *aisleViewNameField_;
    NSPopUpButton *aisleViewStorePopUp_;
    NSBrowser *aisleViewBrowser_;

    // New list view
    NSView *listView_;
    NSTextField *listViewNameField_;
    
    NSArray *categoriesControllerSortDescriptors_;
    NSArray *storePopUpSortDescriptors_;
    NSMutableArray *tabViewSizes_;
    NSMutableSet *categoriesForNewAisle_;
    RNList *listToAddNewItem_;
}
// Top-level elements
@property (nonatomic, assign) IBOutlet NSTabView *tabView;
@property (nonatomic, assign) IBOutlet NSToolbar *toolbar;
@property (nonatomic, assign) IBOutlet NSButton *saveButton;
@property (nonatomic, assign) IBOutlet NSTreeController *categoriesController;
@property (nonatomic, assign) IBOutlet NSArrayController *storesController;

// Category view
@property (nonatomic, assign) IBOutlet NSView *categoryView;
@property (nonatomic, assign) IBOutlet NSTextField *categoryViewNameField;
@property (nonatomic, assign) IBOutlet NSBrowser *categoryViewBrowser;

// Item view
@property (nonatomic, assign) IBOutlet NSView *itemView;
@property (nonatomic, assign) IBOutlet NSTextField *itemViewNameField;
@property (nonatomic, assign) IBOutlet NSBrowser *itemViewBrowser;

// Store view
@property (nonatomic, assign) IBOutlet NSView *storeView;
@property (nonatomic, assign) IBOutlet NSButton *createAislesCheckBox;
@property (nonatomic, assign) IBOutlet NSTextField *storeViewNameField;
@property (nonatomic, assign) IBOutlet NSMatrix *templateMatrix;

// Aisle view
@property (nonatomic, assign) IBOutlet NSView *aisleView;
@property (nonatomic, assign) IBOutlet NSTextField *aisleViewNameField;
@property (nonatomic, assign) IBOutlet NSPopUpButton *aisleViewStorePopUp;
@property (nonatomic, assign) IBOutlet NSBrowser *aisleViewBrowser;

// List view
@property (nonatomic, assign) IBOutlet NSView *listView;
@property (nonatomic, assign) IBOutlet NSTextField *listViewNameField;

// Other properties
@property (nonatomic, retain) NSArray *categoriesControllerSortDescriptors;
@property (nonatomic, retain) NSArray *storePopUpSortDescriptors;
@property (nonatomic, retain) NSMutableArray *tabViewSizes;
@property (nonatomic, retain) NSMutableSet *categoriesForNewAisle;
@property (nonatomic, retain) RNList *listToAddNewItem;

-(void)displayNewItemSheet;
-(void)selectItemWithTag:(NSInteger)tag;
-(IBAction)toolbarItemClicked:(id)sender;
-(IBAction)cancelNewItemSheet:(id)sender;

-(IBAction)saveCategory:(id)sender;
-(IBAction)saveItem:(id)sender;
-(IBAction)saveList:(id)sender;
-(IBAction)saveStore:(id)sender;
-(IBAction)saveAisle:(id)sender;
-(IBAction)aisleBrowserDoubleAction:(id)sender;
-(void)createItemWithString:(NSString *)itemString addToList:(RNList *)list;

-(IBAction)addSelectedSubcategories:(id)sender;
-(IBAction)removeSelectedSubcategories:(id)sender;

@end
